import React from 'react';
import { Form, Row, DatePicker, Button, Select, Input, Col } from 'antd';
const FormItem = Form.Item;
const { RangePicker } = DatePicker;
const { Option } = Select;

const SearchForm = ({ form: { getFieldDecorator, getFieldsValue, setFieldsValue }, onSearch, onClick, advanced, searchItem, resetForm, assemblyGroupList }) => {
  const onHandleAdvanced = () => {
    if (onClick) {
      onClick();
    }
  };

  const onChange = (value, type) => {
    setFieldsValue({ [type]: value })
  }

  const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
      span: 8
    },
    wrapperCol: {
      span: 16
    }
  };
  return (
    <Form className="search-form">
      <Row gutter={24}>
        <Col span={5}>
          <FormItem label="批号"{...formItemLayout}>
            {getFieldDecorator('batchNo', {
              initialValue: searchItem.batchNo || '',
              rules: [{
                required: true,
                message: '请输入批号'
              }],
              getValueFromEvent: (event) => {
                return event.target.value.replace(/\s+/g, "")
              },
            })(
              <Input placeholder='请输入批号' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="物料编码"{...formItemLayout}>
            {getFieldDecorator('partCode', {
              initialValue: searchItem.partCode || '',
              getValueFromEvent: (event) => {
                return event.target.value.replace(/\s+/g, "")
              },
            })(
              <Input placeholder='请输入物料编码' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="图号"{...formItemLayout}>
            {getFieldDecorator('paperCode', {
              initialValue: searchItem.paperCode || '',
              getValueFromEvent: (event) => {
                return event.target.value.replace(/\s+/g, "")
              },
            })(
              <Input placeholder='请输入图号' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
            )}
          </FormItem>
        </Col>
        <Col span={4} style={{ display: 'flex' }} className="serarch-btns">
          <FormItem>
            <Button icon="search" type="primary" onClick={() => onSearch(getFieldsValue())}>
              {'查询'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="primary" icon={advanced ? 'up' : 'down'} onClick={() => onHandleAdvanced()}>
              {'展开'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="default" icon={'redo'} onClick={() => resetForm()}>
              {'重置'}
            </Button>
          </FormItem>
        </Col>
      </Row>
      <Row gutter={24}>

        {
          advanced ? <Col span={5}>
            <FormItem label="组别代码"{...formItemLayout}>
              {/* 20220721 - 输入框改为带搜索下拉 */}
              {/* {getFieldDecorator('groupCode', {
                initialValue: searchItem.groupCode || undefined,
              })(
                <Select placeholder='请选择装配组别代码'
                  allowClear
                  optionFilterProp="children"
                  showSearch
                  filterOption={(input, option) =>
                    option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                  }
                  onChange={(value) => onChange(value, 'assemblyGroup')} >
                  {
                    assemblyGroupList.map(item => {
                      return <Option key={item.groupCode}>{item.groupCode}</Option>
                    })
                  }
                </Select>
              )} */}
              {/* 20221011 - 带搜索下拉改为输入框 */}
              {getFieldDecorator('groupCode', {
                initialValue: searchItem.groupCode || '',
                getValueFromEvent: (event) => {
                  return event.target.value.replace(/\s+/g, "")
                },
              })(
                <Input placeholder='请输入组别代码' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
              )}
            </FormItem>
          </Col> : ''
        }
        {
          advanced ? <Col span={5}>
            <FormItem label="组别名称"{...formItemLayout}>
              {/* 20220721 - 输入框改为带搜索下拉 */}
              {/* {getFieldDecorator('assemblyGroup', {
                initialValue: searchItem.assemblyGroup || undefined,
              })(
                <Select placeholder='请选择装配组别'
                  allowClear
                  optionFilterProp="children"
                  showSearch
                  filterOption={(input, option) =>
                    option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                  }
                  onChange={(value) => onChange(value, 'groupCode')} >
                  {
                    assemblyGroupList.map(item => {
                      return <Option key={item.groupCode}>{item.groupName}</Option>
                    })
                  }
                </Select>
              )} */}
              {/* 20221011 - 带搜索下拉改为输入框 */}
              {getFieldDecorator('assemblyGroup', {
                initialValue: searchItem.assemblyGroup || '',
                getValueFromEvent: (event) => {
                  return event.target.value.replace(/\s+/g, "")
                },
              })(
                <Input placeholder='请输入组别名称' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
              )}
            </FormItem>
          </Col> : ''
        }
      </Row>

    </Form>
  );
};

export default Form.create()(SearchForm);
